/*
 * Copyright (c) 2021 Zsj. All rights reserved.
 */

package com.jzz.crawlerweb.service;

import com.jzz.crawlerweb.handler.data.Captcha;
import com.jzz.crawlerweb.handler.data.TextCaptcha;
import com.jzz.crawlerweb.handler.util.CaptchaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class TextCaptchaService {

    @Autowired
    private CaptchaUtil captchaUtil;

    public byte[] code(HttpServletRequest request) {
        Captcha captcha = captchaUtil.getCaptcha(request);
        if (captcha instanceof TextCaptcha) {
            return ((TextCaptcha) captcha).getRendered();
        }
        return new byte[0];
    }
}
